import 'package:flutter_yn_goods/base/controller/base_list_more_controller.dart';
import 'package:flutter_yn_goods/pages/order/order_add/model/model_order_list.dart';
import 'package:flutter_yn_goods/user/app_user_manager.dart';
import 'package:flutter_yn_goods/utils/http/http_export.dart';
import 'package:flutter_yn_goods/utils/loading/loading_utils.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class OrderLogic extends BaseListMoreController {
  // int page = 1;
  // int limit = 20;
  // RefreshController refreshController = RefreshController(initialRefresh: true);
  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
    // refreshController.dispose();
  }

  // loadData() async {
  //   HttpResponse response = await HttpManager().get(API.getOrderList,
  //       params: {
  //         'page': page,
  //         'limit': limit,
  //       },
  //       // fromJson: ModelHome.fromJson
  //   );
  //   if (response.isSuccess) {
  //     // homeModelRx.value = response.data;
  //     page == 1
  //         ? refreshController.refreshCompleted()
  //         : refreshController.loadComplete();
  //   } else {
  //     page == 1
  //         ? refreshController.refreshFailed()
  //         : refreshController.loadFailed();
  //   }
  // }

  @override
  Future<List> loadData() async {
    HttpResponse response = await HttpManager().get(
      AppUserManager().isLeader() ? API.getOrderList : API.getUserOrderList,
      params: {
        'page': pageNum,
        'limit': pageSize,
        'status': 0,
      },
    );

    return (response.data['list'] as List)
        .map((e) => ModelOrderList.fromJson(e))
        .toList();
    // response.data.keys.contains('list')) {
    //   data = List<T>.from(
    //       (response.data['list'] as List).map((e) => fromJson.call(e)));
    //
    // return [];
  }
}
